package com.banksystem.Interceptor;


import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.ModelAndView;

import com.banksystem.Jwt.JwtKit;
import com.banksystem.Util.RedisUtil;
import com.banksystem.Util.TokenUtil;
import com.banksystem.entity.userinfo;

public class ConfigInterceptor implements HandlerInterceptor{

	@Autowired
	private RedisUtil redis;
	@Autowired
	private TokenUtil TokenUtil;
	
	@Override
	public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler)
			throws Exception {
		String token = TokenUtil.getCookie(request);
		String newtoken = JwtKit.refreshToken(token);
		if(StringUtils.isEmpty(newtoken)){
			request.getRequestDispatcher("/jump.do").forward(request, response);
			return false;
		}
		return true;
	}

	@Override
	public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler,
			ModelAndView modelAndView) throws Exception {
		
	}

	@Override
	public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex)
			throws Exception {
		
		
	}
}
